feat: add claims field to AccessToken for decoded token payload#1165
Closed
robertofalk wants to merge 9 commits intomodelcontextprotocol:mainfrom
Closed
feat: add claims field to AccessToken for decoded token payload#1165robertofalk wants to merge 9 commits intomodelcontextprotocol:mainfrom
robertofalk wants to merge 9 commits intomodelcontextprotocol:mainfrom
Conversation
Author
ochafik
requested changes
Aug 4, 2025
Contributor
ochafik
left a comment
There was a problem hiding this comment.
Hi @robertofalk, thanks for sending this PR!
Currently, there is no JWT payload used to build the AccessToken, afaict.
To handle JWT tokens, you might want to create a new JWTAccessToken / created by a new JWTTokenVerifier (responsible for verifying the token signature), used by a JWT-specific OAuthAuthorizationServerProvider subclass distinct from SimpleOAuthProvider.
(and if we get there, I reckon the non-standard claims should go to a JWTAccessToken.additional_claims field to avoid duplication)
Does this make sense?
Contributor
|
Closing this as per @ochafik's comment this is incomplete and it's been a while since the last update here. If others find this PR and need this, feel free to submit a fresh PR. |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add optional claims dict to AccessToken class to provide access to all decoded JWT claims (both standard and custom) instead of restricting to only specific fields like scopes and expires_at.
Motivation and Context
FastMCP provides a BearerAuthProvider class to validate bearer tokens and returns it using the AccessToken class (https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L387). With the current implementation the claims from the token are limited to the ones defined so far, so any additional claim is not available and to get it currently I had to define an additional middleware that decodes the token again, which is a waste since the token is was already decoded by BearerAuthProvider.
How Has This Been Tested?
I was not able to test it since it's just an attribute that will be used by applications relying on the python-sdk AccessToken class.
Breaking Changes
No, it's an optional attribute.
Types of changes
Checklist
Resolves #1038